goog.provide('dkpoints.raid.RaidDriver');

goog.require('dkpoints.raid.NewRaidView');
goog.require('dkpoints.rpc.RPCService');
goog.require('dkpoints.status.Status');


/**
 * @fileoverview
 *
 * The RaidDriver class is the Presenter in the MVP architecture.  It drives
 * the RaidView class and handles all of the client-server communication.
 */



/**
 * The RaidDriver is responsible for driving both read-only and admin raid
 * views.
 * @param {dkpoints.rpc.RPCService} rpc The RPC service.
 * @param {dkpoints.status.Status} status The Status panel.
 * @param {!Element} bodyContent The body_content element on the page.
 * @constructor
 */
dkpoints.raid.RaidDriver = function(rpc, status, bodyContent) {
  /**
   * @type {dkpoints.rpc.RPCService}
   * @private
   */
  this.rpc_ = rpc;

  /**
   * @type {dkpoints.status.Status}
   * @private
   */
  this.status_ = status;

  /**
   * @type {!Element}
   * @private
   */
  this.bodyContent_ = bodyContent;

  /**
   * Whether or not this driver is currently controlling the UI.
   * @type {boolean}
   * @private
   */
  this.active_ = false;

  /**
   * Whether we are in editable (true) or read-only (false) mode.
   * @type {dkpoints.raid.RaidDriver.State}
   * @private
   */
  this.editableState_ = dkpoints.raid.RaidDriver.State.READ_ONLY;
};


/**
 * @enum {number}
 */
dkpoints.raid.RaidDriver.State = {
  READ_ONLY: 0,
  OFFER_EDITABLE: 1,
  EDITABLE: 2
};


/**
 * Set up an editable view with an empty raid.
 * @param {dkpoints.nav.Path} path The path object for this nav event.
 */
dkpoints.raid.RaidDriver.prototype.createNewRaid = function(path) {
  this.editableState_ = dkpoints.raid.RaidDriver.State.EDITABLE;

  /**
   * this.view_ will be one of the raid view classes (all subclasses of
   * goog.Disposable).
   * @type {goog.Disposable}
   * @private
   */
  this.view_ = new dkpoints.raid.NewRaidView();
};


/**
 * Save state and tear down.
 * @param {function(boolean)} onExit Callback once exit is either
 *    complete or cancelled by the user.  Passing true to the callback means
 *    that the handler has relinquished control of thep age; false means
 *    the user opted not to navigate away.
 */
dkpoints.raid.RaidDriver.prototype.exit = function(onExit) {
  if (this.view_) {
    this.view_.dispose();
  }
  this.active_ = false;
  onExit(true);
};
